<?php
	error_reporting(0);
	require_once('commponents.php');
	class DbConnector extends SystemComponent 
	{
		public $table = 'users';
		private $link;
		private	$theQuery;
		
		public function __construct() 
		{
			$options = parent::getSettings();
			
			$host = $options['dbhost'];
			$db = $options['dbname'];
			$userdb = $options['dbusername'];
			$passdb = $options['dbpassword'];
			
			$this->link = mysql_connect($host, $userdb, $passdb);
			
			$select_db = mysql_select_db($db);
			
			$this->set_names();
			
			if(!$select_db)
			{
				$this->main_check_database();
			}
		}
		public function query($query)
		{
			$this->theQuery = $query;
			return mysql_query($query, $this->link);
		}
		public function fetchObject($result)
		{
			return mysql_fetch_object($result);
		}
		public function close()
		{
			mysql_close($this->link);
		}
		public function numRows($result)
		{
			return mysql_num_rows($result);
		}
		public function set_names()
		{
			$this->query('SET NAMES cp1251');
		}
		private function main_check_database()
		{
			header('Location: error_database.html');
		}
	}
?>